<html>
<head><meta charset="utf-8"><title>How do I get the DefId of an `ast::Item`? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html">How do I get the DefId of an `ast::Item`?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232693107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232693107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232693107">(Apr 01 2021 at 02:03)</a>:</h4>
<p>I'm working on <a href="https://github.com/rust-lang/rust/issues/68427#issuecomment-578526219">https://github.com/rust-lang/rust/issues/68427#issuecomment-578526219</a> if it matters - I need to know which module to resolve things relative to. I don't know how to convert a NodeId to a DefId - I don't think I have a <code>hir::Map</code> available before creating a tcx.</p>



<a name="232693385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232693385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232693385">(Apr 01 2021 at 02:06)</a>:</h4>
<p><code>lower_to_hir</code> steals the resolver so yeah I can't call that</p>



<a name="232693506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232693506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232693506">(Apr 01 2021 at 02:08)</a>:</h4>
<p>hmm I do see <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/struct.Resolver.html#method.local_def_id"><code>Resolver::local_def_id</code></a>, maybe that works?</p>



<a name="232694471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232694471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232694471">(Apr 01 2021 at 02:22)</a>:</h4>
<p>yay it compiles!</p>



<a name="232694475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232694475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232694475">(Apr 01 2021 at 02:22)</a>:</h4>
<p>omg and it runs too</p>



<a name="232694483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232694483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232694483">(Apr 01 2021 at 02:22)</a>:</h4>
<p>wow this is actually quite surprising</p>



<a name="232697124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20DefId%20of%20an%20%60ast%3A%3AItem%60%3F/near/232697124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20DefId.20of.20an.20.60ast.3A.3AItem.60.3F.html#232697124">(Apr 01 2021 at 03:06)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/83738">https://github.com/rust-lang/rust/pull/83738</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>